<?php

/*
	This file is part of Mandragon.

    Mandragon is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Mandragon is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Mandragon.  If not, see <http://www.gnu.org/licenses/>.
*/

require_once 'PHPUnit/Framework.php';
require_once 'autoload.php';

class TestPoll extends PHPUnit_Framework_TestCase {

	function test_get_edit_body() {
		$expected_id = 321;
		$expected_sql = 'sql';
		$expected_sql_result = 'sql result';
		$expected_result = 'result';
		$expected_news_item = array('body' => $expected_result);

		$page = new Page();
		$event = new Poll($page, $expected_id);

		$mock_db_access = $this->getMock('DbAccessor');
		$mock_db_access->expects($this->once())
				->method('db_query_select')
				->with(array(array('*')), array("POLL"), "item_id = $expected_id")
				->will($this->returnValue($expected_sql));
		$mock_db_access->expects($this->once())
				->method('db_do_query')
				->with($expected_sql)
				->will($this->returnValue($expected_sql_result));
		$mock_db_access->expects($this->once())
				->method('db_fetch_array')
				->with($expected_sql_result)
				->will($this->returnValue($expected_news_item));
		$event->set_db_accessor($mock_db_access);

		$actual = $event->get_edit_body();

		$this->assertEquals($expected_result, $actual);
	}
}


?>
